package com.sm.appbase.base;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * BaseFragment
 */
public abstract class BaseFragment extends Fragment {

    public FragmentActivity mActivity;
    private View mContentView;
    public Context mContext;
    public Unbinder unbinder;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mContentView = inflater.inflate(getLayoutId(), container, false);
        unbinder = ButterKnife.bind(this, mContentView);
        mActivity = getActivity();
        mContext = getContext();
        initParams(getArguments());
        initView();
        return mContentView;
    }

    public abstract void initParams(Bundle bundle);

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    protected abstract int getLayoutId();

    protected abstract void initView();

    protected void initData() {
    }

    public View getContentView() {
        return mContentView;
    }
}